import {axios} from "../utils/request";

const ScheduleMixin  =   {

    data() {
        return {
            course: {
                routers: {
                    index: 'api/course',
                    detail: (id) => { return `${this.course.routers.index}/${id}`; },
                    periods: course => { return `${this.course.routers.index}/${course}/period`; },
                },
                //  查询参数
                queryParams: {like: '', mode: '', type: '',},
                //  课程类型参数
                types: [],
                //  课程模式参数
                mode: [],
                //  table列参数
                columns: [
                    {
                        title: '课程名称',
                        dataIndex: 'LABEL',
                        scopedSlots: {customRender: 'label'},
                        // fixed: 'left',
                        width: '100px',
                        align: 'left',

                    },
                    {
                        title: '所属类型',
                        dataIndex: 'TYPE',
                        scopedSlots: {customRender: 'types'},
                        width: '20%',
                        align: 'left',
                    },
                    {
                        title: '课程模式',
                        dataIndex: 'MODE',
                        scopedSlots: {customRender: 'mode'},
                        width: '12%',
                        align: 'left',
                    },
                    {
                        title: '创建人',
                        dataIndex: 'created',
                        scopedSlots: {customRender: 'member'},
                        width: '8%',
                        align: 'center',
                    },
                    {
                        title: '更新时间',
                        dataIndex: 'updated_at',
                        align: 'center',
                        width: '16%',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        // fixed: 'right',
                        scopedSlots: {customRender: 'action'},
                        width: '10%',
                        align: 'right',
                    }
                ],
                //  操作参数
                operate: {
                    title: '添加课程',
                    visible: false,
                    data: {},
                    formItemLayout: {
                        labelCol: {span: 6},
                        wrapperCol: {span: 14},
                    },
                    form: this.$form.createForm(this),
                    type: 'create',
                    submitBtn: {
                        loading: false,
                        disabled: false
                    },
                },
                //
                lists: false,
                loadCourseList: parameter => {
                    if( this.course.lists === false ) {
                        this.$http.get(this.course.routers.index, {params: parameter}).then(res => {
                            this.course.lists = res.data;
                        });
                    }
                    return this.course.lists;
                },
            },
            period: {
                routers: {
                    index: 'api/period',
                    detail: (id) => { return `${this.period.routers.index}/${id}`; },
                    sections: (id) => { return `${this.period.routers.detail(id)}/section`; },
                    exams: (id) => { return `${this.period.routers.detail(id)}/exam`; },
                    batchStore: (id) => { return `${this.period.routers.detail(id)}/batchStore`; },
                    publish: (id) => { return `${this.period.routers.detail(id)}/publish`; },
                    students: (id) => { return `${this.period.routers.detail(id)}/student`; },
                    studentsJoin: (id, group = false) => {
                        return group ? `${this.period.routers.students(id)}/join/${group}` : `${this.period.routers.students(id)}/join`;
                    },
                    studentsDrop: (id, group = false) => {
                        return group ? `${this.period.routers.students(id)}/drop/${group}` : `${this.period.routers.students(id)}/drop`;
                    },
                },
                //  table参数
                columns: [
                    {
                        title: '课期名称',
                        dataIndex: 'LABEL',
                        scopedSlots: {customRender: 'label'},
                        width: '20%',
                        align: 'left',
                    },
                    {
                        title: '状态',
                        dataIndex: 'PUBLISHED_AT',
                        scopedSlots: {customRender: 'published'},
                        align: 'center',
                        width: '16%',
                    },
                    {
                        title: '更新时间',
                        dataIndex: 'updated_at',
                        align: 'center',
                        width: '16%',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        fixed: 'right',
                        scopedSlots: {customRender: 'action'},
                        width: '10%',
                        align: 'right',
                    }
                ],
                //  操作参数
                operate: {
                    title: '添加课期',
                    visible: false,
                    data: {},
                    formItemLayout: {
                        labelCol: {span: 6},
                        wrapperCol: {span: 14},
                    },
                    form: this.$form.createForm(this),
                    type: 'create',
                    submitBtn: {
                        loading: false,
                        disabled: false
                    },
                    course: {}
                },
                //  详情操作参数
                detailOperate: {
                    visible: false,
                    title: '',
                    course: {},
                    period: {},
                    sections: [],
                },
                //  批量排课
                batch: {
                    visible: false,
                    form: this.$form.createForm(this),
                    data: {},
                    submitBtn: {
                        loading: false,
                        disabled: false
                    },
                },
            },
            section: {
                routers: {
                    index: 'api/section',
                    detail: (id) => { return `${this.section.routers.index}/${id}`; },
                    update: (id) => { return this.section.routers.detail(id); },
                    destroy: (id) => { return this.section.routers.detail(id); },
                    status: (id, status) => { return `${this.section.routers.detail(id)}/status/${status}`; },
                    video: (id) => { return `${this.section.routers.detail(id)}/video`; },
                    homework: (id) => {return `${this.section.routers.detail(id)}/homework`;},
                },
                columns: [
                    {
                        title: '课时',
                        dataIndex: 'LABEL',
                        scopedSlots: {customRender: 'label'},
                        width: '10%',
                        // fixed: 'left',
                        align: 'left',
                    },
                    {
                        title: '教员',
                        dataIndex: 'teacher',
                        scopedSlots: {customRender: 'teacher'},
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '资源',
                        dataIndex: 'resource',
                        scopedSlots: {customRender: 'resource'},
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '上课时间',
                        dataIndex: 'start_at_diff',
                        scopedSlots: {customRender: 'start'},
                        align: 'center',
                        width: '20%',
                    },
                    {
                        title: '来源',
                        dataIndex: 'FROM',
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '状态',
                        dataIndex: 'STATUS',
                        scopedSlots: {customRender: 'status'},
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '视频',
                        dataIndex: 'VIDEO',
                        scopedSlots: {customRender: 'video'},
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '作业',
                        dataIndex: 'HOMEWORK',
                        scopedSlots: {customRender: 'homework'},
                        align: 'center',
                        width: '10%',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        fixed: 'right',
                        scopedSlots: {customRender: 'action'},
                        width: '10%',
                        align: 'right',
                    }
                ],
                selectedRowKeys: [],
                selectedRows: [],

                // custom table alert & rowSelection
                options: {
                    alert: {
                        show: true, clear: () => {
                            this.selectedRowKeys = [];
                            this.selectedRows = []
                        }
                    },
                    rowSelection: {
                        selectedRowKeys: this.selectedRowKeys,
                        onChange: this.onSelectChange
                    }
                },
                optionAlertShow: true,
                loadData: parameter => {
                    return this.$http.get(
                        this.period.routers.sections(this.period.detailOperate.period.ID), Object.assign(parameter, {})
                    ).then(res => {
                        return {
                            pageNo: parameter.pageNo,
                            pageSize: parameter.pageSize,
                            totalCount: res.count,
                            totalPage: res.count / parameter.pageSize,
                            data: res.data,
                        }
                    })
                }
            },
            student: {
                loadData: parameter => {
                    return this.$http.get(
                        this.period.routers.students(this.period.detailOperate.period.ID), Object.assign(parameter, {})
                    ).then(res => {
                        return res;
                    })
                },
                lists: [],
                columns: [
                    {
                        title: '课期名称',
                        dataIndex: 'LABEL',
                        scopedSlots: {customRender: 'label'},
                        width: '20%',
                        align: 'left',
                    },
                    {
                        title: '状态',
                        dataIndex: 'PUBLISHED_AT',
                        scopedSlots: {customRender: 'published'},
                        align: 'center',
                        width: '16%',
                    },
                    {
                        title: '更新时间',
                        dataIndex: 'updated_at',
                        align: 'center',
                        width: '16%',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        fixed: 'right',
                        scopedSlots: {customRender: 'action'},
                        width: '10%',
                        align: 'right',
                    }
                ],
                showJoin: false,
                loading: false,
            },
            group: {
                routers: {
                    index: 'api/group',
                    join: (group = null) => {
                    },
                },
            },
            exam: {
                loading: false,
                list: [],
                operate: {
                    visible: false,
                    form: this.$form.createForm(this),
                    data: {},
                    submitBtn: {
                        loading: false,
                        disabled: false
                    },
                    title: '创建考试',
                    type: 'create',
                }
            },
            teacher: {
                router: {
                    index: 'api/teacher'
                },
                lists: false,
                loadTeacherList: parameter => {
                    if( this.teacher.lists === false ) {
                        this.$http.get(this.teacher.router.index, {params: parameter}).then(res => {
                            if( res.code === 0 ) {
                                this.teacher.lists = res.data;
                            }
                        });
                    }
                    return this.teacher.lists;
                }
            },
            resource: {
                router: {
                    index: 'api/resource'
                },
                lists: false,
                loadResourceList: parameter => {
                    if( this.resource.lists === false ) {
                        this.$http.get(this.resource.router.index, {params: parameter}).then(res => {
                            if( res.code === 0 ) {
                                this.resource.lists = res.data;
                            }
                        });
                    }
                    return this.resource.lists;
                }
            },
        };
    },

    methods: {

    }
};

export { ScheduleMixin };
